//
//  UserViewController.swift
//  LaiLang
//
//  Created by David on 2017/2/3.
//  Copyright © 2017年 David. All rights reserved.
//

import UIKit

class UserViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    let rowTitles = ["我的课表", "我的电费", "我的赞", "我的收藏", "评论相关"]
    
    
    var tableView: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "我"
        
        tableView = UITableView(frame: view.frame, style: .grouped)
        tableView.delegate = self
        tableView.dataSource = self
        view.addSubview(tableView)
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 2{
            return rowTitles.count
        }
        return 1
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        switch indexPath.section {
        case 0:
            return 64
        case 1:
            return 64
        default:
            return 44
        }
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: .default, reuseIdentifier: "item")
        switch indexPath.section {
        case 0:
            if indexPath.row == 0{
                let avatar = UIImageView(frame: CGRect(x: 16, y: 8, width: 48, height: 48))
                avatar.backgroundColor = UIColor.lightGray
                avatar.layer.cornerRadius = 24
                cell.addSubview(avatar)
                
                let nameLabel = UILabel(frame: CGRect(x: 72, y: 8, width: view.bounds.width - 72 - 16, height: 20))
                nameLabel.text = "用户"
                cell.addSubview(nameLabel)
                
                let infoLabel = UILabel(frame: CGRect(x: 72, y: 36, width: view.bounds.width - 72 - 16, height: 20))
                infoLabel.font = UIFont.systemFont(ofSize: 16)
                infoLabel.textColor = UIColor.lightGray
                infoLabel.text = "查看或编辑个人资料"
                cell.addSubview(infoLabel)
                
                
            }
            break
        case 1:
            if indexPath.row == 0{
                let lBtn1 = UIButton(type: .system)
                lBtn1.frame = CGRect(x: 0, y: 0, width: view.bounds.width/3, height: 64)
                lBtn1.setTitle("233\n生活", for: .normal)
                lBtn1.titleLabel?.numberOfLines = 0
                lBtn1.titleLabel?.textAlignment = .center
                cell.addSubview(lBtn1)
                
                let lBtn2 = UIButton(type: .system)
                lBtn2.frame = CGRect(x: view.bounds.width/3, y: 0, width: view.bounds.width/3, height: 64)
                lBtn2.setTitle("233\n我关注的人", for: .normal)
                lBtn2.titleLabel?.numberOfLines = 0
                lBtn2.titleLabel?.textAlignment = .center
                cell.addSubview(lBtn2)
                
                let lBtn3 = UIButton(type: .system)
                lBtn3.frame = CGRect(x: view.bounds.width/3*2, y: 0, width: view.bounds.width/3, height: 64)
                lBtn3.setTitle("233\n我关注的频道", for: .normal)
                lBtn3.titleLabel?.numberOfLines = 0
                lBtn3.titleLabel?.textAlignment = .center
                cell.addSubview(lBtn3)
                
                let border1 = UIView(frame: CGRect(x: view.bounds.width/3 - 1, y: 0, width: 1, height: 64))
                border1.backgroundColor = UIColor.lightGray
                cell.addSubview(border1)
                
                let border2 = UIView(frame: CGRect(x: view.bounds.width/3*2 - 1, y: 0, width: 1, height: 64))
                border2.backgroundColor = UIColor.lightGray
                cell.addSubview(border2)
            }
            break
        case 2:
            cell.textLabel?.text = rowTitles[indexPath.row]
            break
        default:
            break
        }
        return cell
    }

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 1
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
